package org.example.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @BelongsProject：blockchain-APTrace
 * @CreateTime 2024-06-06-17:12
 * @Author SweetPig
 */
@Configuration
@Lazy
@Slf4j
public class ThreadPoolExecutor {
    //最大线程数
    public static final int MAX_POOL_SIZE = 20;
    //核心线程数
    public static final int CORE_POOL_SIZE = 20;
    public static final int KEEP_ALIVE_SECONDS = 60;
    public static final int QUEUE_CAPACITY = 100;

    public static final String THREAD_NAME_PREFIX = "DC-";

    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //最大线程数
        executor.setMaxPoolSize(MAX_POOL_SIZE);
        //核心线程数
        executor.setCorePoolSize(CORE_POOL_SIZE);
        //线程空闲存活时间
        executor.setKeepAliveSeconds(KEEP_ALIVE_SECONDS);
        //线程队列容量
        executor.setQueueCapacity(QUEUE_CAPACITY);
        //设置线程名称前缀
        executor.setThreadNamePrefix(THREAD_NAME_PREFIX);
        //初始化线程
        executor.initialize();
        return executor;
    }

}
